extends Control



onready var edit_input = $ParagraphForm/value/edit
onready var type_op = $ParagraphForm/value/VBoxContainer/HBoxContainer/OptionButton


const template1 = {
	"action_type":0,
	"target_type":2,
	"target_type_id":130
}
const template2 = {
	"action_type":1,
	"target_type":2,
	"target_type_id":130,
	"x":100,
	"y":100,
	"show_visiable":"show/hide"
}

const template3 = {
	"action_type":2,
	"target_type":2,
	"target_type_id":130,
	"start_dialog_id":"对话文件的id"
}

const template4 = {
	"action_type":3,
	"target_type":2,
	"target_type_id":130,
	"move_dir":[1,1,2,2,3,3],
	"has_wait":false
}

const template5 = {
	"action_type":4,
	"target_type":2,
	"target_type_id":130,
	"face_direction":1
}

const template6 = {
	"action_type":5,
	"camera_one": true,
	"camera_reset": false,
	"target_position":[100,100]
}

const template7 = {
	"action_type":6,
	"sound_file": "res://xxx/xxx/xxa.ogg/wav/mid",
	"sound_type": "sound / background",
	"sound_key":"随便写一个字符串，必须全局唯一",
	"wait":true
}

const template8 = {
	"action_type":7,
	"mode":"show/hide"
}

const template9 = {
	"action_type":8,
	"signal_conf":{
		"name":"dialog_monster_fight/dialog_npc_fight",
		"value":{
			"npc_fight_id":1,
			"poke_id":1,
			"level":1,
			"format_id":"gen7customfieldsinglegame/gen7customfielddoublegame/gen7customfieldmobmonstergame",
			"other_data":{}
		},
	}
}

const template10 = {
	"action_type":9,
	"time":2.0
}

const template11 = {
   "action_type": 10,
   "target_type": 1,
   "target_type_id":19,
   "move_dir":[
	  {
		 "condition_id":-1,
		 "condition_x":80,
		 "condition_y":48,
		 "path": [1,4,4,4,4],
		 "desc":"npc移动路线1"
	  },
	  {
		 "condition_id":-1,
		 "condition_x":64,
		 "condition_y":64,
		 "path": [1,1,4,4,4,4,4],
		 "desc":"npc移动路线2"
	  },
	  {
		 "condition_id":-1,
		 "condition_x":80,
		 "condition_y":80,
		 "path": [1,1,1,4,4,4,4],
		 "desc":"npc移动路线3"
	  },
	  {
		 "condition_id":-1,
		 "condition_x":96,
		 "condition_y":64,
		 "path": [1,4,4],
		 "desc":"npc移动路线4"
	  }
   ],
   "desc": "指定19号这个npc,进行多路径规则移动,1,2,3,4代表上下左右"
}

const template12 = {
	
}

const template13 = {
   "action_type": 12,
   "target_type": 1,
   "target_type_id":19,
   "face_dir":[
	  {
		 "condition_id":-1,
		 "condition_x":80,
		 "condition_y":48,
		 "face_direction":1
	  },
	  {
		 "condition_id":-1,
		 "condition_x":64,
		 "condition_y":64,
		 "face_direction":1
	  },
	  {
		 "condition_id":-1,
		 "condition_x":80,
		 "condition_y":80,
		 "face_direction":1
	  },
	  {
		 "condition_id":-1,
		 "condition_x":96,
		 "condition_y":64,
		 "face_direction":1
	  }
   ],
   "desc": "指定19号这个npc,根据玩家坐标位置进行朝向更改"
}




func _ready():
	update_help(0)


func get_help(id):
	id = id + 1
	var helps =  [
		{
			"desc": "代表不需要做任何操作，请删除右侧所有内容",
			"template": ""
		},{
			"desc": "显示一个感叹号，门也可以，多用于npc。",
			"template": JSON.print(template1, "\t")
		},
		{
			"desc": "示指定当前地图上的一个实体\n进行隐藏与显示",
			"template": JSON.print(template2, "\t")
		},
		{
			"desc": "弹出一个对话，等同于你跟npc对话",
			"template": JSON.print(template3,"\t")
		},
		{
			"desc": "指定当前地图上的一个实体，进行移动",
			"template": JSON.print(template4,"\t")
		},
		{
			"desc": "让实体或者玩家改变朝向",
			"template": JSON.print(template5,"\t")
		},
		{
			"desc": "相机移动",
			"template": JSON.print(template6,"\t")
		},
		{
			"desc": "播放音乐",
			"template": JSON.print(template7, "\t")
		},
		{
			"desc": "可以黑屏后执行一些操作，例如修改npc的位置等。\n避免出现npc闪现的问题。",
			"template": JSON.print(template8, "\t")
		},
		{
			"desc": "马上开启一场战斗 剧本会自动结束并向后端发起完成此剧本，注意填写`otherData`的数据",
			"template": JSON.print(template9, "\t")
		},
		{
			"desc": "有时候表演执行太快，这里可以让剧本稍作停留，等待哪些不阻碍的子项运行一段时间。",
			"template": JSON.print(template10, "\t")
		},
		{
			"desc": "判断另一个实体的位置然后移动到它的身边",
			"template": JSON.print(template11, "\t")
		},
		{
			"desc": "有时候需要将玩家的状态进行修改，虽然对话也可以完成，但是剧本提供一个就避免显示对话框",
			"template": JSON.print(template12, "\t")
		},
		{
			"desc": "实体进行判断规则更改朝向",
			"template": JSON.print(template13, "\t")
		},
	]
	
	
	return helps[id]
	

func update_help(id, template=false):
	if id < 0 or id > 13:
		id = 0
	
	var help =  get_help(id)
	$ParagraphForm/value/VBoxContainer/Label.text = help["desc"]
	


func set_data(data):
	if data:
		edit_input.text = JSON.print(data,"\t")
		var action_type = data["action_type"]
		type_op.select(type_op.get_item_index(action_type))
	
	update_help(type_op.get_selected_id())

 # 将当前组件数据构建为元数据
func get_data():
	return str2var(edit_input.text)


func _on_OptionButton_item_selected(index):
	update_help(type_op.get_selected_id())


func _on_useTemplate_button_up():
	var id = type_op.get_selected_id()
	if id < 0 or id > 13:
		id = 0
	
	var help =  get_help(id)
	edit_input.text = help["template"]


func _on_del_button_up():
	queue_free()
